import cache from '@/plugins/cache'

const useAppStore = defineStore('app', {
  state: () => ({
    sidebar: {
      opened: cache.session().get('vv__sidebarStatus', true),
      withoutAnimation: false,
      hide: false
    },
    device: 'desktop',
    size: cache.local().get('vv__element_size', 'default')
  }),
  actions: {
    toggleSideBar(withoutAnimation) {
      if (this.sidebar.hide) {
        return false
      }
      this.sidebar.opened = !this.sidebar.opened
      this.sidebar.withoutAnimation = withoutAnimation
      cache.local().set('vv__sidebarStatus', !!this.sidebar.opened)
    },
    closeSideBar({ withoutAnimation }) {
      cache.local().set('vv__sidebarStatus', false)
      this.sidebar.opened = false
      this.sidebar.withoutAnimation = withoutAnimation
    },
    toggleDevice(device) {
      this.device = device
    },
    setSize(size) {
      this.size = size
      cache.local().set('vv__element_size', size)
    },
    toggleSideBarHide(status) {
      this.sidebar.hide = status
    }
  }
})

export default useAppStore
